package com.panfeng.xcloud.scheduler.util;

import cn.hutool.core.util.StrUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class OrderNoGenerate {

    public static String getOrderIdByTime(String prefix) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
        String newDate = sdf.format(new Date());
        StringBuilder strBuilder = StrUtil.builder();
        Random random = new Random();
        if (StrUtil.isNotBlank(prefix)) {
            strBuilder.append(prefix);
        }
        strBuilder.append(newDate);
        for (int i = 0; i < 3; i++) {
            strBuilder.append(random.nextInt(10));
        }
        return strBuilder.toString();
    }

    public static String getOrderIdByTime() {
        return getOrderIdByTime(null);
    }

    public static String getOrderNo() {
        return getOrderIdByTime("P");
    }

    public static String getSubOrderNo() {
        return getOrderIdByTime("S");
    }

    public static void main(String[] args) {
        System.err.println(OrderNoGenerate.getOrderIdByTime());
    }

}